package com.atguigu.flink.streamapi.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Smexy on 2022/11/19
 *
 *      从文件中读取
 */
public class Demo2_FileSource
{
    public static void main(String[] args) {

        
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //从本地读取文件，文件编码默认必须是 UTF-8
        //DataStreamSource<String> ds = env.readTextFile("data/words.txt");


        //可以是一个文件，也可以是一个目录
        //DataStreamSource<String> ds = env.readTextFile("data/");

        //从外部的文件系统读取，例如hdfs
        //UnsupportedFileSystemSchemeException: Hadoop is not in the classpath/dependencies.
        //默认不会引入hadoop客户端，如果读取hdfs，需要手动引入
        DataStreamSource<String> ds = env.readTextFile("hdfs://hadoop102:9820/input");

        ds.print();


        try {
                    env.execute();
                } catch (Exception e) {
                    e.printStackTrace();
                }
        
    }
}
